home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / GoTo < prev    next >
Encoding:
Text File  |  1991-08-16  |  2.3 KB  |  74 lines  |  [TEXT/MPS ]

  1. #----------------------------------------------------------------------------------------------------------------------------------------------------
  2. #    GoTo
  3. #    MPW Shell Script
  4. #    Written by Gina Cherry • August 16, 1991
  5. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  6. #    
  7. #    Usage:
  8. #        GoTo [LineNumber] [Window]
  9. #        
  10. #    Function:
  11. #        GoTo positions the cursor at the beginning of the specified line number in the specified window.  If no line
  12. #        number is specified, GoTo prompt the user for a line number.  If no window is specified, GoTo 
  13. #        operates on the target window.
  14. #
  15. #    Note: GoTo can be added to the Find menu with the following command:
  16. #
  17. #            AddMenu Find 'GoTo/7' ∂
  18. #                        'GoTo "{Active}"'
  19. #----------------------------------------------------------------------------------------------------------------------------------------------------
  20.  
  21. # Make sure there are no more than 2 parameters.
  22.     If {#} > 2                                                        
  23.         Echo "### Usage: {0} [LineNumber] [Window]"     
  24.         Exit 1
  25.     End >> Dev:StdErr
  26.  
  27. # Don't exit on error.
  28.     Set Exit 0    
  29.  
  30. # Initialize variables.
  31.     Set Window ""    
  32.     Set LineNum ""                                                                
  33.  
  34. # Loop through parameters.
  35.     For Item in {"Parameters"}
  36.         
  37.         # If the parameter consists of numbers, it is the line number.
  38.             If "{Item}" =~ /[0-9]+/
  39.                 If {LineNum} == ""
  40.                     Set LineNum "{Item}"
  41.                 Else
  42.                     Echo "### Line number multiply defined."
  43.                     Echo "### Usage: {0} [LineNumber] [Window]"     
  44.                     Exit 1
  45.                 End  
  46.         # Otherwise, the parameter is the name of the window.
  47.             Else                                                                             
  48.                 If {Window} == ""
  49.                     Set Window "{Item}"
  50.                 Else
  51.                     Echo "### Window multiply defined."
  52.                     Echo "### Usage: {0} [LineNumber] [Window]"     
  53.                     Exit 1
  54.                 End  
  55.             End >> Dev:StdErr
  56.     End
  57.  
  58. # If no window name was given on the command line, Window is the target window.
  59.     If  "{Window}" == ""                                                        
  60.         Set Window "{Target}"
  61.     End
  62.  
  63. #    Extract the leaf name of the window, and store in ®1.    
  64.     (Evaluate "{Window}" =~/:*([¬:]+:*)*([¬:]+)®1/) ∑ Dev:Null
  65.     
  66.  
  67. # If no line number was specified, prompt the user for a line number. 
  68.     If "{LineNum}" == ""                                                        
  69.         Set LineNum `Request "Go to what line in {®1}?" || Exit 0` > Dev:Null
  70.     End
  71.  
  72. # Position cursor at the beginning of line number LineNum in the window Window.    
  73. #    Note: If Window is not a valid window, Find will write an error message to standard error.
  74.     Find Δ"{LineNum}" "{Window}"